package com.arceus.leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * @author : iron
 * @version : 1.0.0
 * @date : 11:49 PM 2019/3/2
 */

public class t13 {

    public static int romanToInt(String s) {

        Map<Character, Integer> map = new HashMap<>();
        map.put('I', 1);
        map.put('V', 5);
        map.put('X', 10);
        map.put('L', 50);
        map.put('C', 100);
        map.put('D', 500);
        map.put('M', 1000);

        char[] word = s.toCharArray();
        int sum = 0;
        for (int i = 0; i < word.length; i++) {

            if (i != word.length - 1) {
                if (map.get(word[i]) < map.get(word[i + 1])) {
                    sum += map.get(word[i + 1]) - map.get(word[i]);
                    i++;
                    continue;
                }
            }

            sum += map.get(word[i]);
        }
        return sum;
    }

    public static void main(String[] args) {
        romanToInt("IVIIVI");
    }
}
